package com.example.flowable.controller;

import com.example.flowable.service.LeaveProcessService;
import jakarta.annotation.Resource;
import org.flowable.task.api.Task;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/process")
public class ProcessController {

    @Resource
    private LeaveProcessService processService;

    @PostMapping("/start")
    public ResponseEntity<String> startProcess(
            @RequestParam String userId,
            @RequestParam int days) {
        String processId = processService.startProcess(userId, days);
        return ResponseEntity.ok("流程已启动，ID：" + processId);
    }

    @GetMapping("/tasks")
    public List<Task> getTasks(@RequestParam String userId) {
        return processService.getUserTasks(userId);
    }

    @PostMapping("/complete")
    public void completeTask(
            @RequestParam String taskId,
            @RequestParam boolean approved) {
        processService.completeTask(taskId, approved);
    }
}